﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Zhaoxi.Industrial.Base
{
    public class NotifyPropertyBase : INotifyPropertyChanged
    {
        //创建一个委托
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// CallerMemberName 触发这个委托的名称会自动赋值给propName
        /// </summary>
        /// <param name="propName"></param>
        public void RaisePropertyChanged([CallerMemberName]string propName = "") 
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
        }

        public void Set<T>(ref T field, T value, [CallerMemberName] string propName = "") {
            //if (field.Equals(value))
            //{
            //    return;
            //}

            field = value;// UIelement = value值
            RaisePropertyChanged(propName);
        }
    }
}
